package com.web.dao;

import com.web.controller.web.WebCarouselController;
import com.web.entity.Carousel;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class CarouselSqlProvider {


    public String insertSelective(Carousel record) {
        BEGIN();
        INSERT_INTO("t_carousel");

        if (record.getType() != null) {
            VALUES("type", "#{type,jdbcType=VARCHAR}");
        }

        if (record.getStoreName() != null) {
            VALUES("store_name", "#{storeName,jdbcType=VARCHAR}");
        }

        if (record.getGoodsPicture() != null) {
            VALUES("goods_picture", "#{goodsPicture,jdbcType=VARCHAR}");
        }

        if (record.getActivityPicture() != null) {
            VALUES("activity_picture", "#{activityPicture,jdbcType=VARCHAR}");
        }

        if (record.getActivityName() != null) {
            VALUES("activity_name", "#{activityName,jdbcType=VARCHAR}");
        }

        if (record.getActivityUrl() != null) {
            VALUES("activity_url", "#{activityUrl,jdbcType=VARCHAR}");
        }

        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(Carousel record) {
        BEGIN();
        UPDATE("t_carousel");

        if (record.getType() != null) {
            SET("type = #{type,jdbcType=VARCHAR}");
        }

        if (record.getStoreName() != null) {
            SET("store_name = #{storeName,jdbcType=VARCHAR}");
        }

        if (record.getGoodsPicture() != null) {
            SET("goods_picture = #{goodsPicture,jdbcType=VARCHAR}");
        }

        if (record.getActivityPicture() != null) {
            SET("activity_picture = #{activityPicture,jdbcType=VARCHAR}");
        }

        if (record.getActivityName() != null) {
            SET("activity_name = #{activityName,jdbcType=VARCHAR}");
        }

        if (record.getActivityUrl() != null) {
            SET("activity_url = #{activityUrl,jdbcType=VARCHAR}");
        }

        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }



    public String selectAllCarousel(WebCarouselController.CarouselColumns record) {
        BEGIN();
        SELECT("id");
        SELECT("type");
        SELECT("store_name");
        SELECT("goods_picture");
        SELECT("activity_picture");
        SELECT("activity_name");
        SELECT("activity_url");
        SELECT("status");
        SELECT("create_time");
        SELECT("modify_time");
        FROM("t_carousel");

        if (record.getActivityName() != null&&!"".equals(record.getActivityName())) {
            WHERE("activity_name like #{activityName,jdbcType=VARCHAR}");
        }
        if (record.getStatus() != null&&!"".equals(record.getStatus())) {
            WHERE("status = #{status,jdbcType=INTEGER}");
        }

        if (record.getStoreName() != null&&!"".equals(record.getStoreName())) {
            WHERE("store_name like #{storeName,jdbcType=VARCHAR}");
        }
        if (record.getType() != null&&!"".equals(record.getType())) {
            WHERE("type = #{type,jdbcType=INTEGER}");
        }

        ORDER_BY("modify_time desc");

        return SQL();
    }

}